@extends('home.parent')
@section('title','修改密码')
@section('head_js')
@endsection
@section('head_css')
@endsection
@section('content')
    <style>
        #update_password_form span.showPwd{
            position:absolute;top:10px;right:10px;cursor:pointer;color:#009688;
        }
    </style>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                <small></small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{{URL('admin')}}"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li class="active"><a href="{{URL('admin/update/password')}}">修改密码</a></li>
            </ol>
        </section>
        <div class="login-box">
            <div class="login-logo">
                <a href="{{URL('admin/update/password')}}">修改密码</a></li>
            </div>
            <div class="login-box-body">
                <div class="callout callout-danger" id="login-box-msg" style="display:none;">
                    <h4 id="show_error_msg"></h4>
                </div>
                <form action="" method="post" id="update_password_form">
                    <div class="form-group has-feedback">
                        <input type="password" id="password" name="password" class="form-control" placeholder="原密码" required>
                        <!--<span class="glyphicon glyphicon-lock form-control-feedback"></span>-->
                        <span class="fa fa-eye showPwd"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" id="new_password" name="new_password" class="form-control" placeholder="新密码" required>
                        <!--<span class="glyphicon glyphicon-lock form-control-feedback"></span>-->
                        <span class="fa fa-eye showPwd"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" class="form-control" id="repassword" name="repassword" placeholder="确认新密码" required>
                        <!--<span class="glyphicon glyphicon-log-in form-control-feedback"></span>-->
                        <span class="fa fa-eye showPwd"></span>
                    </div>
                    <div class="row">
                        <div class="col-xs-4">
                            <button type="button" class="btn btn-primary btn-block btn-flat" onclick="update_password_form()">提 交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('foot_js')
    <script src="{{ asset('/js/tools.js') }}"></script>
    <script type="text/javascript">
        function update_password_form(){
            var password = $.trim($("#password").val());
            var new_password = $.trim($("#new_password").val());
            var repassword = $.trim($("#repassword").val());
            if(password == ''){
                $('#show_error_msg').html('请输入原密码');
                $("#login-box-msg").show();
                return false;
            }
            if(new_password == ''){
                $('#show_error_msg').html('请输入新密码');
                $("#login-box-msg").show();
                return false;
            }
            if(repassword == ''){
                $('#show_error_msg').html('请确认新密码');
                $("#login-box-msg").show();
                return false;
            }
            if(password.length <6 || new_password.length < 6 || repassword < 6) {
                $('#show_error_msg').html('密码不能少于6位');
                $("#login-box-msg").show();
                return false;
            }
            if(!puppet.checkusrandpwd(password) || !puppet.checkusrandpwd(new_password) || !puppet.checkusrandpwd(repassword)){
                $("#show_error_msg").html("密码含有非法字符");
                $("#login-box-msg").show();
                return false;
            }
            if(new_password != repassword){
                $("#show_error_msg").html("两次密码输入不一致");
                $("#login-box-msg").show();
                return false;
            }
            if(new_password == password){
                $("#show_error_msg").html("新密码不能与原密码相同");
                $("#login-box-msg").show();
                return false;
            }
            var url = "{{URL('admin/update/password/ajax')}}";
            var data = {password:password,new_password:new_password};
            var data = puppet.myajax('post',url,data,false);
            if(data.code == true){
                $("#show_error_msg").html(data.message);
                $("#login-box-msg").show();
                return false;
            }else{
                layer.msg("修改成功", {icon: 6});
                setTimeout('window.location.href="/"',1000);
            }
        }
        //查看密码
        $('.showPwd').hover(function(){
            $(this).removeClass('fa-eye');
            $(this).addClass('fa-eye-slash');
            $(this).parent().children('input').attr('type','text');
        },function(){
            $(this).removeClass('fa-eye-slash');
            $(this).addClass('fa-eye');
            $(this).parent().children('input').attr('type','password');
        });
    </script>
@endsection